<template>
  <view class="normal-login-container">
    <view class="logo-content align-center justify-center flex">
      <image style="width: 180rpx;height: 180rpx;" src="@/static/images/logo.png" mode="widthFix"></image>
      <text class="title"></text>
    </view>
    <view class="login-form-content">
      <view class="input-item flex align-center">
        <view class="iconfont icon-user icon"></view>
        <input v-model="form.phone" class="input" type="number" placeholder="请输入手机号" maxlength="11" />
      </view>
      <view class="input-item flex align-center">
        <view class="iconfont icon-password icon"></view>
        <input v-model="form.password" :type="showPwd ? 'text' : 'password'" class="input" placeholder="请输入密码" maxlength="20" />
        <view class="eye-icon" @click="showPwd = !showPwd">
          <text v-if="showPwd">🙈</text>
          <text v-else>👁️</text>
        </view>
      </view>
      <view class="forgot-pwd" @click="onForgotPwd">忘记密码?</view>
      <view class="action-btn">
        <button class="login-btn cu-btn block bg-blue lg round" :disabled="!agree" :class="{ 'btn-disabled': !agree }" @click="handleLogin">登录</button>
      </view>
      <view class="xieyi text-center xieyi-custom">
        <view class="custom-checkbox" :class="{ checked: agree }" @click="agree = !agree">
          <text v-if="agree" class="checkmark">✔</text>
        </view>
        <text :class="['xieyi-text', agree ? 'green' : 'grey']">
          我同意并遵守
          <text @click="handleUserAgrement" class="xieyi-link">《使用协议》</text>
          <text @click="handlePrivacy" class="xieyi-link">《隐私协议》</text>
        </text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      form: {
        phone: '',
        password: ''
      },
      showPwd: false,
      agree: false
    }
  },
  methods: {
    handleLogin() {
      if (!this.agree) {
        uni.showToast({ title: '请先同意协议', icon: 'none' });
        return;
      }
      if (!/^1[3-9]\d{9}$/.test(this.form.phone)) {
        uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
        return;
      }
      if (!this.form.password) {
        uni.showToast({ title: '请输入密码', icon: 'none' });
        return;
      }
      // 登录逻辑
      uni.showLoading({ title: '登录中...' });
      setTimeout(() => {
        uni.hideLoading();
        uni.showToast({ title: '登录成功', icon: 'success' });
        // 跳转主页等
      }, 1000);
    },
    handleUserAgrement() {
      uni.showToast({ title: '用户协议', icon: 'none' });
    },
    handlePrivacy() {
      uni.showToast({ title: '隐私协议', icon: 'none' });
    },
    onForgotPwd() {
      this.$tab.navigateTo('/pages/forget')
    }
  }
}
</script>

<style lang="scss" scoped>
page {
  background-color: #ffffff;
}

.normal-login-container {
  width: 100%;

  .logo-content {
    width: 100%;
    font-size: 21px;
    text-align: center;
    padding-top: 8%;

    image {
      border-radius: 4px;
    }

    .title {
      margin-left: 10px;
    }
  }

  .login-form-content {
    text-align: center;
    margin: 20px auto;
    margin-top: 15%;
    width: 80%;

    .input-item {
      margin: 20px auto;
      background-color: #f5f6f7;
      height: 45px;
      border-radius: 20px;
      // 移除高亮边框
      // border: 1px solid #ffa500;

      .icon {
        font-size: 38rpx;
        margin-left: 10px;
        color: #999;
      }

      .input {
        width: 100%;
        font-size: 14px;
        line-height: 20px;
        text-align: left;
        padding-left: 15px;
        outline: none !important;
        box-shadow: none !important;
        border: none !important;
        background: transparent;
      }
      .input:focus {
        outline: none !important;
        box-shadow: none !important;
        border: none !important;
        background: transparent;
      }
    }

    .login-btn {
      margin-top: 40px;
      height: 45px;
    }

    .reg {
      margin-top: 15px;
    }

    .xieyi {
      color: #333;
      margin-top: 20px;
    }

    .login-code {
      height: 38px;
      float: right;

      .login-code-img {
        height: 38px;
        position: absolute;
        margin-left: 10px;
        width: 200rpx;
      }
    }

    .login-btn:disabled,
    .btn-disabled {
      background: #b0c4de !important;
      color: #fff !important;
      opacity: 0.7;
    }
    .get-code-btn {
      margin-left: 10px;
      height: 32px;
      line-height: 32px;
      padding: 0 10px;
      font-size: 13px;
      border-radius: 16px;
      background: #f5f6f7;
      color: #007aff;
      border: none;
    }
  }
}

.password-login-link {
  text-align: center;
  color: #666;
  font-size: 16px;
  margin: 18px 0 0 0;
  cursor: pointer;
}

.xieyi-custom {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  margin-top: 20px;

  .custom-checkbox {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid #bbb;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    transition: border-color 0.2s;
    font-size: 16px;
    cursor: pointer;
    box-sizing: border-box;
    .checkmark {
      color: #e43d33;
      font-size: 16px;
      font-weight: bold;
    }
  }
  .custom-checkbox.checked {
    border-color: #4caf50; // 绿色
    background: #fff;
  }
  .custom-checkbox .checkmark {
    color: #4caf50; // 绿色
  }
  .xieyi-text.red {
    color: #4caf50; // 绿色
  }
  .xieyi-link {
    color: #4caf50; // 绿色
  }
  .xieyi-text {
    font-size: 15px;
    line-height: 1.5;
    &.grey {
      color: #999;
    }
    &.red {
      color: #e43d33;
    }
    .xieyi-link {
      color: #e43d33;
      margin: 0 2px;
      cursor: pointer;
    }
  }
}
.other-login-divider {
  display: flex;
  align-items: center;
  margin: 40px 0 20px 0;
  .line {
    flex: 1;
    height: 1px;
    background: #eee;
  }
  .other-login-text {
    margin: 0 12px;
    color: #999;
    font-size: 14px;
  }
}
.other-login-btns {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 20px;
  .other-login-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #f5f6f7;
    display: flex;
    align-items: center;
    justify-content: center;
    .other-login-icon {
      width: 32px;
      height: 32px;
    }
  }
}
</style>
